using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

/// <summary>
/// 该类用于计算GUI位置相关信息
/// </summary>
[System.Serializable]
public class GUIPosition
{
    //绘制控件
    private Rect rPos = new Rect(0,0,100,100);
    //屏幕九宫格对其方式
    public E_Alignment_Type screen_Alignment_Type = E_Alignment_Type.Center;
    //偏移位置
    public Vector2 offSet;
    //宽高
    public float width = 100;
    public float height = 50;

    //计算最终相对坐标位置
    private void CalcPos()
    {
        switch (screen_Alignment_Type)
        {
            case E_Alignment_Type.Up:
                rPos.x = offSet.x + Screen.width / 2 - width / 2;
                rPos.y = offSet.y;
                break;
            case E_Alignment_Type.Down:
                rPos.x = offSet.x + Screen.width / 2 - width / 2;
                rPos.y = offSet.y + Screen.height - height;
                break;
            case E_Alignment_Type.Left:
                rPos.x = offSet.x;
                rPos.y = offSet.y + Screen.height / 2 - height / 2;
                break;
            case E_Alignment_Type.Right:
                rPos.x = offSet.x + Screen.width - width;
                rPos.y = offSet.y + Screen.height/2 - height / 2;
                break;
            case E_Alignment_Type.Center:
                rPos.x = offSet.x + Screen.width/2 - width / 2;
                rPos.y = offSet.y + Screen.height/2 - height / 2;
                break;
            case E_Alignment_Type.Left_Up:
                rPos.x = offSet.x;
                rPos.y = offSet.y;
                break;
            case E_Alignment_Type.Left_Down:
                rPos.x = offSet.x;
                rPos.y = offSet.y + Screen.height - height;
                break;
            case E_Alignment_Type.Right_Up:
                rPos.x = offSet.x + Screen.width - width;
                rPos.y = offSet.y;
                break;
            case E_Alignment_Type.Right_Down:
                rPos.x = offSet.x + Screen.width - width;
                rPos.y = offSet.y + Screen.height - height;
                break;
        }
    }
    //得到最终位置与宽高
    public Rect Pos
    {
        get 
        {
            CalcPos();
            rPos.width = width; 
            rPos.height = height;
            return rPos; 
        }
    }
}
